function powerTree(divID, expandAll) {
    var data;
    $.ajax({
        type: "post"
        , url: "sys/power/manager/s/imygwPower.imy"
        , dataType: "json"
        , async: false //取消异步
        , success: function(d) {
            data = d;
        }
    });
    var setting = {
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "pid",
                name: "text",
                rootPId: 0
            }, key: {
                name: "text"
            }
        }
        , check: {
            enable: true,
            chkStyle: "checkbox"
        }
        , view: {
            dblClickExpand: false
        }
    };
    var treeObj = $.fn.zTree.init($(divID), setting, data);
    if (expandAll) {
        treeObj.expandAll(true);
    } else {
        var nodes = treeObj.getNodesByParam("pid", "0", null);
        if (nodes.length > 0) {
            treeObj.expandNode(nodes[0], true, false, false);
        }
    }
}
function setPowerTree(treeObjID, nodeID) {
    var treeObj = $.fn.zTree.getZTreeObj(treeObjID);
    var node = treeObj.getNodeByParam("id", nodeID, null);
    treeObj.checkNode(node, true, false);
}
function zt_check(treeObjID, ischeck) {
    var treeObj = $.fn.zTree.getZTreeObj(treeObjID);
    treeObj.checkAllNodes(ischeck);
}

function getPowerTreeCheckID(treeObjID) {
    var treeObj = $.fn.zTree.getZTreeObj(treeObjID);
    var nodes = treeObj.getCheckedNodes(true);
    var ids = "";
    for (var i = 0; i < nodes.length; i++) {
        ids = ids + "," + nodes[i].id;
    }
    return ids.substring(1);
}
